import logging
import yaml
import json
import sys
import os

class Config:
    """
    Load System Configs from Config.yaml file into global paramters
    """

    def __init__(self, path_to_config):
        
        self.path_to_config = path_to_config

        if os.path.isfile(self.path_to_config):
            pass
        else:
            self.path_to_config = '../{}'.format(self.path_to_config)

        with open(self.path_to_config, "r") as f:
            dictionary = yaml.safe_load(f.read())
        
        for k, v in dictionary.items():
            setattr(self, k, v)
    
    def get(self, name):
        """
        获取属性变量
        """
        return getattr(self, name, None)




# 单件模式 
# 软件启动相关配置
config_singleton = Config("sys_config.yaml")

# 模型相关配置
config_model_singleton = Config("model_config.yaml")